﻿@page
@model FileUploadModel
@{
    ViewData["Title"] = "上传文件";
}
<form id="uploadForm">
    <input type="text" id="businessType" name="businessType" placeholder="业务类型">
    <input type="file" id="file" name="file">
    <button type="button" onclick="uploadFile()">上传</button>
</form>

@section Scripts {
    <script type="text/javascript">
        async function uploadFile() {
            const formData = new FormData();
            formData.append('businessType', document.getElementById('businessType').value);
            formData.append('file', document.getElementById('file').files[0]);

            try {
                const response = await fetch('/api/Upload/UploadFile', {
                    method: 'POST',
                    body: formData
                });

                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }

                const data = await response.json();
                console.log(data);
                alert(`文件上传成功！\n业务类型：${data.businessType}\n文件名: ${data.fileName}`);
            } catch (error) {
                console.error('There was a problem with your fetch operation:', error);
                alert('Failed to upload file.');
            }
        }
    </script>
}
